package indi.wshape1.takeawaydeliveryinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import indi.wshape1.takeawaydeliveryinfo.mapper.AdminMapper;
import indi.wshape1.takeawaydeliveryinfo.pojo.Admin;
import indi.wshape1.takeawaydeliveryinfo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wshape1
 * @description 针对表【admin】的数据库操作Service实现
 * @since 2023-01-17 12:57:25
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
        implements AdminService {

    @Autowired
    @SuppressWarnings("all")
    private AdminMapper adminMapper;

    @Override
    public boolean verify(String phone, String password) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        Admin admin = getOne(queryWrapper);
        if (admin != null) {
            return password.equals(admin.getPassword());
        }
        return false;
    }

    @Override
    public List<Admin> getListByBlockNameAndKeyword(String blockName, String keyword) {

        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.and((q) ->
                q.like("name", keyword).or()
                        .like("phone", keyword).or()
                        .like("block_name", keyword));

        if (blockName != null) {
            queryWrapper.and((q) -> q.eq("block_name", blockName));
        }
        return list(queryWrapper);
    }

    @Override
    public int freeAdminBatchByBlockIds(List<Integer> ids) {
        return adminMapper.updateBlockNameBatchByBlockIds("null", ids);
    }
}




